FILE_TYPE = 0
DIR_TYPE = 1


class BaseObject(object):
    """Represents a persistent object in database.
    
    Sub-classes may redefine:

        - `__slots__`: the attributes of the business object.

    """
    __slots__ = ('_dirty',)

    def __init__(self, **kwargs):
        for k in self.__slots__:
            try:
                object.__setattr__(self, k, kwargs[k])
            except KeyError:
                object.__setattr__(self, k, None)

        self._dirty = set()

    def __setattr__(self, name, value):
        if name != '_dirty':
            self._dirty.add(name)

        object.__setattr__(self, name, value)

    def asdict(self):
        return dict([(k, getattr(self, k)) for k in BaseObject.__slots__ + self.__slots__])

    def __repr__(self):
        return '%s %s' % (object.__repr__(self), self.asdict())

class Storage(BaseObject):
    __slots__ = ('id', 'name')

class File(BaseObject):
    __slots__ = ('id', 'storage', 'name', 'file_type', 'parent')

